package com.gpframework.module.purchase.domain.req;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gpframework.common.utils.DateUtils;
import com.gpframework.common.utils.StringUtils;
import com.gpframework.module.base.domain.req.BaseReq;
import com.gpframework.module.purchase.domain.GpPurchaseGramWeight;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import java.math.BigDecimal;

import java.util.Date;

/**
 * @ClassName GpPurchaseGramWeightReq
 * @Author gpframework
 * @Date 2024-01-09
 * @Version 1.0.0
 * @Description 列表查询信息体
 */
@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@Accessors(chain = true)
public class GpPurchaseGramWeightReq extends BaseReq {
    private static final long serialVersionUID = 1L;

         @ApiModelProperty("来料检验单id")
     private Long incomingInspectId;
     @ApiModelProperty("订单号")
     private String sn;
     @ApiModelProperty("检测时间")
     private Date checkTime;
     @ApiModelProperty("批号")
     private String batchNo;
     @ApiModelProperty("产品基础表id")
     private Long produceProductId;
     @ApiModelProperty("产品名")
     private String productName;
     @ApiModelProperty("颜色")
     private String colour;
     @ApiModelProperty("到货克重（g/m²）")
     private BigDecimal arrivalWeight;
     @ApiModelProperty("标准克重（g/m²）")
     private BigDecimal standardWeight;
     @ApiModelProperty("检测人id")
     private Long checkId;
     @ApiModelProperty("检测人名称")
     private String checkName;
    @ApiModelProperty("查询条件（订单号/客户名）")
    private String searchName;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date searchDate;

    /**
    * @Description 生成查询wrapper
    * @Author greatplan@qq.com
    * @Date 2020-11-04 16:04
    * @Param [lqw]
    * @Param [isVO] 是否vo查询体，true的话走的是mapper.xml里面的查询语句，不过查询语法还是mybatis-plus，主要用于某些关联查询出一些非数据表字段
    * @Return void
    */
    public void generatorQuery(QueryWrapper<GpPurchaseGramWeight> lqw,boolean isVo) {
        String alias = "";
        if (isVo) {
            alias = "gp.";
            lqw.eq(alias+"del_status",0);
            lqw.orderByDesc(alias + "create_time");
        }
        if (this.getIncomingInspectId() != null){
        lqw.eq(alias+"incoming_inspect_id" ,this.getIncomingInspectId());
        }
        if (StringUtils.isNotBlank(this.getSn())){
            lqw.like(alias+"sn",this.getSn());
        }
        if (this.getCheckTime() != null){
        lqw.eq(alias+"check_time" ,this.getCheckTime());
        }
        if (StringUtils.isNotBlank(this.getBatchNo())){
            lqw.like(alias+"batch_no",this.getBatchNo());
        }
        if (this.getProduceProductId() != null){
        lqw.eq(alias+"produce_product_id" ,this.getProduceProductId());
        }
        if (StringUtils.isNotBlank(this.getProductName())){
            lqw.like(alias+"product_name",this.getProductName());
        }
        if (StringUtils.isNotBlank(this.getColour())){
            lqw.like(alias+"colour",this.getColour());
        }
        if (this.getArrivalWeight() != null){
        lqw.eq(alias+"arrival_weight" ,this.getArrivalWeight());
        }
        if (this.getStandardWeight() != null){
        lqw.eq(alias+"standard_weight" ,this.getStandardWeight());
        }
        if (this.getCheckId() != null){
        lqw.eq(alias+"check_id" ,this.getCheckId());
        }
        if (StringUtils.isNotBlank(this.getCheckName())){
            lqw.like(alias+"check_name",this.getCheckName());
        }
        if (StringUtils.isNotBlank(this.getSearchName())) {
            lqw.and(wrapper -> wrapper.like("gp.sn", this.getSearchName()).or().like("gp.product_name", this.getSearchName()).or().like("gp.product_color", this.getSearchName()));
        }
        if (this.getSearchDate() != null) {
            lqw.apply("DATE_FORMAT(gp.create_time, '%Y-%m-%d') = '" + DateUtils.dateTime(this.getSearchDate()) + "'");
        }
    }
}
